// 获取商品
var oProduct = document.querySelector(".product");
(function(){
const xhr = new XMLHttpRequest();
xhr.open("get","http://chst.vip:1234/api/getcoupon");
xhr.send(null);
xhr.onreadystatechange = function(){
    if(xhr.readyState === 4 && xhr.status === 200){
        var res = JSON.parse(xhr.responseText);
        console.log(res);
        var rex = res.result;
        var ele =""
        rex.forEach(item => {
            ele += `
            <div  couponid=${item.couponId}>
            <p  couponid=${item.couponId}>${item.couponTitle}</p>
            </div>
            `
        });
        oProduct.innerHTML = ele;
    }
    
}
// 点击事件
oProduct.onclick = function(event){
    var e = event || window.event;
    var target = e.target || e.srcElement;
    console.log(target);
    var _this;
    if(target.nodeName !="IMG"){
        _this = target.parentNode;
    }else{
        _this = target;
    }
    var id = target.getAttribute("couponid");
    console.log(id);
    location.href = "../html/优惠券详情.html?couponid="+id;
}
$(".gotop").click(function(){
    $("body,html").animate({scrollTop:0},1000)
});
})();